# coding:utf-8
import arcpy
import json

arcpy.env.overwriteOutput = True

path_names = ["path_time","hispath_time"]
paths = [r"F:\1.DT\文件\桌面\chongqing\设计\Park_vehicle_management\data\path\path.shp",r"F:\1.DT\文件\桌面\chongqing\设计\Park_vehicle_management\data\path\hispath.shp"]
outpaths = [r"F:\1.DT\文件\桌面\chongqing\设计\Park_vehicle_management\data\path_point\path.shp",r"F:\1.DT\文件\桌面\chongqing\设计\Park_vehicle_management\data\path_point\hispath.shp"]

def creat_point(path,outpath):
    arcpy.GeneratePointsAlongLines_management(path, outpath, Distance='10 meters')

def creat_json(outpath,path_name):
    with arcpy.da.SearchCursor(outpath,["ORIG_FID"]) as sur:
        path_num = set()
        for row in sur:
            path_num.add(row[0])
        path_num = list(path_num)

        path_json = {}
        for i in path_num:
            path_json[i] = []

    with arcpy.da.SearchCursor(outpath, ["ORIG_FID", "x", 'y']) as sur:
        for row in sur:
            index = path_num.index(row[0])
            # path_json[index].append([row[1]+0.00005,row[2]+0.00003])
            path_json[index].append([row[1],row[2]])

    for key in path_json:
        time = 0
        for xy in path_json[key]:
            xy.append(time)
            time += 1
    print(len(path_json))

    with open(f"../json/{path_name}.json", "w") as josn_file:
        json.dump(path_json,josn_file)

for i in range(2):
    # pass
    creat_json(outpaths[i],path_names[i])